package com.mmy.controller.hotel;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.mmy.domain.hotel.THotelPlan;
import com.mmy.service.impl.hotel.HotelBaseServiceImpl;
import com.mmy.service.impl.hotel.HotelPlanServiceImpl;

@Controller
public class HotelPlanController {
	@Autowired
	HotelPlanServiceImpl hotelPlanServiceImpl;
	@Autowired
	HotelBaseServiceImpl hotelBaseServiceImpl;

	/**
	 * 函数功能说明： 景区预留页根据时间查询ScenicPlan
	 *
	 * @param 参数说明
	 * @return 返回值说明 VScenicPlan
	 * @author 创建人 hanxl
	 * @date 创建日期 2021.03.02
	 */
	@ResponseBody
	@RequestMapping("/queryplanhotel")
	public Map<String, Object> QueryPlan(@RequestParam("date") Date date, @RequestParam("roomID") String strRoomID) {

		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String strNowDate = dateFormat.format(date);
		List<Map<String, Object>> result = hotelPlanServiceImpl.findPlanValidMap(Integer.parseInt(strRoomID),
				strNowDate);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("service", result);
		return map;
	}

	/**
	 * 函数功能说明：景区预留页查询价格
	 *
	 * @param 参数说明
	 * @return 返回值说明 String
	 * @author 创建人 hanxl
	 * @date 创建日期 2021.03.02
	 */
	@ResponseBody
	@RequestMapping("/querypriceroom")
	public String TestQueryRoomPrice(@RequestParam("plan") String strJson) {

		List<THotelPlan> lstHotelPlan = JSON.parseArray(strJson, THotelPlan.class);
		// logger.info(lstScenicPlan.toString());
		BigDecimal total = new BigDecimal("0");
		for (THotelPlan tHotelPlan : lstHotelPlan) {
			// logger.info(tScenicPlan.toString());
			Integer planID = tHotelPlan.getPlanID();
			THotelPlan dbHotelPlan = hotelPlanServiceImpl.findByPlanID(planID.toString());
			BigDecimal price = dbHotelPlan.getPrice();
			Integer num = tHotelPlan.getNumber();
			BigDecimal sum = price.multiply(BigDecimal.valueOf(num));
			total = total.add(sum);
		}
		return total.toString();
	}
}
